﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using ValidationFramework.Reflection;

namespace ValidationFramework.Configuration.Fluent
{
	/// <summary>
	/// During this step a consumer will create a rule with a specified validator and add it to the provided policy.
	/// </summary>
	/// <remarks>This is an extensibility point for the fluent config. Consumers can write extension methods for this 
	/// class to create thier own fluent api's for thier custom validators</remarks>
	public class RuleCreationStep<TValidating>
	{
		/// <summary>
		/// Cached rule location options. (created earlier in the fluent config)
		/// </summary>
		private RuleLocation _ruleLocation;

		public RuleCreationStep(RuleLocation ruleLocation)
		{
			_ruleLocation = ruleLocation;
		}

		/// <summary>
		/// Make this inernal so it can't be seen by consumers using the fluent API.
		/// </summary>
		/// <returns></returns>
		internal Rule CreateRule(ISpecification validator)
		{
			return _ruleLocation.CreateRule(validator);
		}

		/// <summary>
		/// Specifies a validator for the rule being configured
		/// </summary>
		/// <param name="validator"></param>
		/// <remarks>Default way to specify a validator. This is not very fluent. Create your own extension methods for better readability.</remarks>
		public DefaultSpecificationConfigurationStep<TValidator, TValidating> Passes<TValidator>(TValidator validator) where TValidator : ISpecification
		{
			return new DefaultSpecificationConfigurationStep<TValidator, TValidating>(this, validator);
		}
	}
}
